package com.martin.lib_base.base

import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.LinearLayoutManager
import com.martin.lib_base.R
import com.martin.lib_base.common.CommonAdapter
import com.martin.lib_base.databinding.FragmentBaseListBinding
import com.martin.lib_base.interfaces.IGetData
import com.martin.lib_base.model.PageModel

/**
 * @desc：基础列表页面
 */
abstract class BaseListFragment : BaseFragment<FragmentBaseListBinding>(), IGetData {

    //页码工具
    val pageModel = PageModel()

    override fun layoutId() = R.layout.fragment_base_list

    override fun initOnViewCreated() {
        binding.rv.adapter = CommonAdapter(requireContext(), getViewHolders())
        binding.rv.layoutManager = getLayoutManager()

        pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, this, this)

        getData()
    }

    /**
     * 获取列表item视图持有者列表
     */
    abstract fun getViewHolders(): List<Class<out BaseViewHolder<*, out ViewDataBinding>>>

    /**
     * 获取布局管理者
     */
    open fun getLayoutManager() = LinearLayoutManager(requireContext())
}